import { NextResponse } from 'next/server'
import prisma from '@/lib/database-prisma'

export async function GET() {
  try {
    // 尝试连接数据库
    const userCount = await prisma.user.count()
    
    return NextResponse.json({ 
      status: 'ok', 
      timestamp: new Date().toISOString(),
      service: 'todo-app',
      environment: {
        NODE_ENV: process.env.NODE_ENV,
        DATABASE_URL: process.env.DATABASE_URL ? 'configured' : 'missing',
        NEXTAUTH_URL: process.env.NEXTAUTH_URL
      },
      database: {
        connected: true,
        userCount
      }
    }, { status: 200 })
  } catch (error) {
    return NextResponse.json({ 
      status: 'error', 
      timestamp: new Date().toISOString(),
      service: 'todo-app',
      environment: {
        NODE_ENV: process.env.NODE_ENV,
        DATABASE_URL: process.env.DATABASE_URL ? 'configured' : 'missing',
        NEXTAUTH_URL: process.env.NEXTAUTH_URL
      },
      database: {
        connected: false,
        error: error instanceof Error ? error.message : 'Unknown error'
      }
    }, { status: 500 })
  }
} 